package com.casa.POI.dianping;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Property;


public class FetchListSearchUrlsExecutor extends CityExecutor {
	
	public FetchListSearchUrlsExecutor(int cityId) {
		super(cityId);
	}

	@Override
	public void execute() {
		super.execute();
		Session s = SessionManager.getInstance().openSession();
		Criteria c = s.createCriteria(City.class);
		c.add(Property.forName("id").eq(getCityId()));
		c.setMaxResults(1);
		City city = (City) c.uniqueResult();
		String url = "/mylist/" + city.getPinyin();
		ListSearchUrl searchUrl = new ListSearchUrl(url, getCityId());
		if (s.get(ListSearchUrl.class, url) == null) {
			s.beginTransaction();
			s.saveOrUpdate(searchUrl);
			s.getTransaction().commit();
			printStatus("add " + url);
		}
		s.close();
	}
	
	public static void main(String[] args) {
		new FetchListSearchUrlsExecutor(149).execute();
	}

}
